<template>
    <div v-if="showMsgBoxs" class="mag-box" @click="cancleMsg">
        <transition enter-active-class="animated bounceInDown" leave-active-class="animated bounceOutUp">
            <div class="mask-div">
                <div class="msg-tip">
                    <div class="msg-title">
                        <p>提示</p>
                        <p @click="confirmMsgs">x</p>
                    </div>
                    <div class="msg-content">
                        {{ msgTip }}
                    </div>
                    <div class="msg-btn-group flex-end">
                        <div v-show="msgType == 2" class="msg-btn cancle-btn" @click="confirmMsgs">
                            <p>取消</p>
                        </div>
                        <div v-show="msgType == 1" class="msg-btn confirm-btn" @click="confirmMsgs">
                            <p>确定</p>
                        </div>
                        <div v-show="msgType == 0 || msgType == 2" class="msg-btn confirm-btn" @click="confirmMsg">
                            <p>确定</p>
                        </div>
                    </div>
                </div>
            </div>
        </transition>
    </div>
</template>
  
<script>
export default {
    name: "MsgBox",
    props: {
        showMsgBox: {
            type: Boolean,
            default: false,
        },

        msgTip: {
            type: String,
            default: "",
        },
        msgType: {
            type: Number,
            default: 0,
        },
    },
    watch: {
        showMsgBox: {
            handler(newVal) {
                if (newVal) {
                    this.showMsgBoxs = newVal;
                }
            },
            immediate: true,
        },
    },
    data() {
        return {
            // msgTip: '',
            showMsgBoxs: false,
            //   msgType: '', // 0 带功能确定  1 无功能确定  2 带动能确定、取消    3整个组件不显示
            success: "",
            cancle: "",
        };
    },
    methods: {
        open({ msgTip, msgType = 1, success, cancle }) {
            this.showMsgBoxs = true;
            this.msgType = msgType;
            this.msgTip = msgTip;
            this.success = success;
            this.cancle = cancle;
        },
        confirmMsgs() {
            // this.showMsgBoxs = false
            this.$emit("confirmMsg", this.showMsgBoxs);
            // this.success()
            // 组件关闭后销毁该组件
            // this.remove()
        },
        confirmMsg() {
            // this.showMsgBoxs = false
            this.$emit("confirmMsgs", this.showMsgBoxs);
            // this.success()
            // 组件关闭后销毁该组件
            // this.remove()
        },
        cancleMsg() {
            this.showMsgBoxs = false;
            this.$emit("confirmMsg", this.showMsgBoxs);
            // this.cancle();
            // this.remove();
        },
    },
};
</script>
<style scoped lang="less">
.mask-div {
    position: fixed;
    width: 100%;
    height: 100%;
    z-index: 5000;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: rgba(32, 42, 59, 0.5);
}

.msg-tip {
    width: 378px;
    height: 145px;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16);
    background: #ffffff;
    border-radius: 4px;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    z-index: 9999;
}

.msg-title {
    width: 100%;
    height: 36px;
    // background-color: #1f95ee;
    border-radius: 4px 4px 0 0;
    padding: 0 15px;
    margin-bottom: 0;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;

    p {
        color: #303133;
        font-size: 18px;
        line-height: 36px;
        // text-align: center;
    }

    p:nth-child(2) {
        color: #ccc;
        font-size: 14px;
    }
}

.msg-content {
    // padding: 20px;
    width: 100%;
    box-sizing: border-box;
    font-size: 14px;
    color: red;

    padding: 10px 15px;
    color: #606266;
    font-size: 14px;
}

.msg-btn-group {
    position: absolute;
    bottom: 10px;
    right: 12px;
    display: flex;

    .msg-btn {
        // padding: 6px 10px;
        cursor: pointer;
        border-radius: 4px;

        p {
            font-size: 12px;
            border-radius: 4px;
        }
    }

    .cancle-btn {
        background: #fff;
        border: 1px solid #dcdfe6;
        color: #606266;
        width: 50px;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 30px;
        line-height: 30px;
    }

    .confirm-btn {
        background-color: #006adb;
        border: 1px solid #006adb;
        width: 50px;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 30px;
        line-height: 30px;
        color: #fcfcfc;
        margin-left: 10px;
    }
}
</style>
  
  